<template>
	<div>
		<el-form ref="form" :model="form" :rules="rules" label-width="80px">
			
			<el-row>
				<el-col :span="10">
					<el-form-item label="客户姓名" prop="customerName">
				<el-input v-model="form.customerName"></el-input>
			</el-form-item>
				</el-col>
				
				<el-col :span="10">
					<el-form-item label="护理项目" prop="nursingProject"  label-width="130px">
				<el-input v-model="form.nursingProject"></el-input>
			</el-form-item>
				</el-col>
			</el-row>
			
			<el-row>
				<el-col :span="10">
					<el-form-item label="护理时间" prop="nursingTime" label-width="80px">
						<el-date-picker v-model="form.nursingTime" value-format="yyyy-MM-dd HH:mm:ss" type="datetime"
							placeholder="选择日期时间">
						</el-date-picker>
					</el-form-item>
				</el-col>

				<el-col :span="10">
					<el-form-item label="数量" prop="number" label-width="100px">
						<el-input v-model="form.number"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			
			
			<el-row>
				<el-col :span="10">
					<el-form-item label="护理内容">
				<el-input v-model="form.content"></el-input>
			</el-form-item>
				</el-col>
				
				<el-col :span="10">
					<el-form-item label="护理人员" label-width="130px">
				<el-input v-model="form.nursingStaff"></el-input>
			</el-form-item>
				</el-col>
			</el-row>
			
			<el-row></el-row>

			<el-form-item>
				<el-button type="primary" plain @click="save">保存数据</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
	import axios from '@/utils/axiosutils.js';
	export default {
		name: 'nurserecordAdd',
		props: ['editid'],
		components: {},
		data() {
			return {
				form: {
					customerName: '',
					nursingProject: '',
					nursingTime: '',
					number: '',
					content: '',
					nursingStaff: ''
				},
				rules: {
					customerName: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					nursingProject: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					nursingTime: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					number: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
				},
			};
		},
		created() {
			if (this.editid) {
				// 如果是修改 用户名输入框禁用
				this.isupdate = true;
				axios.get(
					'/nurseRecords/getById',
					response => {
						console.log(response)
						this.form.id = this.editid;
						this.form.customerName = response.obj.customerName;
						this.form.nursingProject = response.obj.nursingProject;
						this.form.nursingTime = response.obj.nursingTime;
						this.form.number = response.obj.number;
						this.form.content = response.obj.content;
						this.form.nursingStaff = response.obj.nursingStaff;
					}, {
						id: this.editid
					}
				);
			}
		},
		methods: {
			save: function() {
				if (this.editid) {
					axios.post(
						'/nurseRecords/update',
						resp => {
							this.$emit('update:show', false);
							this.$emit('getData');
						},
						this.form
					);
				} else {
					axios.post(
						'/nurseRecords/add',
						resp => {
							this.$emit('update:show', false);
							this.$emit('getdata');
						},
						this.form
					);
				}
			}
		}
	};
</script>

<style></style>
